const connection = require('../app/database')

class FileService {
  async createAvatar(mimeType, filename, size, id) {
    const statement = `
      INSERT INTO avatar (mimetype, filename, size, user_id) VALUES (?,?,?,?)
    `
    const result = await connection.execute(statement, [mimeType, filename, size, id])
    return result
  }

  async createFiles(filename,mimetype,size,userId,momentId){
    // console.log(filename,mimetype,size,userId,momentId)
    const statement = `
    INSERT INTO file (filename,mimetype,size,moment_id,user_id) VALUES (?,?,?,?,?)
    `
    await  connection.execute(statement, [filename,mimetype,size,momentId,userId])
  }

  async getFileInfo(filename){
    console.log(filename+'2')
    const statement = `
    SELECT * FROM file WHERE filename = ?
    `
    const [result] = await connection.execute(statement,[filename])
    console.log(result)
    return result.pop()
  }

}

module.exports = new FileService()